// pages/cardbark/waitpayment/waitpayment.js
let app = getApp();
let testAddr = app.globalData.testAddr;
let imgurl = app.globalData.imgurl
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr: [{
      id: "0",
      logname: "全部"
    },
    {
      id: "1",
      logname: "待支付"
    },
    {
      id: "2",
      logname: "待发货"
    },
    {
      id: "3",
      logname: "待收货"
    },
    {
      id: "4",
      logname: "待评价"
    }
    ],
    currentTabsIndex: 0,
    allorderlist: [],
    pageIndex: 1,
    orderID: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var guestID = options.guestID
    var orderid = options.orderid
    that.setData({
      orderid: orderid,
      guestID: guestID
    })
    wx.setNavigationBarTitle({
      title: options.statname,
    })
    that.lookorder()
    that.allrefund()
  },
  // 查询订单和状态
  lookorder: function () {
    var that = this
    var pageIndex = that.data.pageIndex
    var allorderlist = that.data.allorderlist
    var orderid = that.data.orderid
    app.util.request({
      url: testAddr + "facility_order/getOrderList?guestID=" + 55 + "&pageIndex=" + pageIndex + "&orderStatus=" + orderid + "&pageSize=" + 5,
      method: "POST",
      data: {},
      success: function (res) {
        var orderlist = res.data
        if (orderlist.length != 0) {
          that.setData({
            pageIndex: pageIndex + 1
          })
        }
        for (var i = 0; i < orderlist.length; i++) {
          orderlist[i].offer.offerDetailImg = imgurl + 'offer/' + orderlist[i].offer.offerDetailImg
        }
        allorderlist = allorderlist.concat(orderlist)
        that.setData({
          allorderlist: allorderlist
        })
      }
    })
  },
  // 查询退款退货订单列表
  allrefund:function(){
    var that =this
    var guestID = that.data.guestID
    app.util.request({
      url: testAddr + "facility_order/getRefundReplace?guestID=" + 55 + "&operationType=" + 1 +"&pageIndex="+1,
      method:"POST",
      data:{},
      success:function(res){
        var refundlist=res.data 
        for (var i = 0;i<refundlist.length;i++ ){
          refundlist[i].offerDetailImg = imgurl + 'offer/' +refundlist[i].offerDetailImg;
        }
        that.setData({
          refundlist: refundlist
        })
        console.log(refundlist)
      }
    })
  },
  // 删除订单
  delorder: function (e) {
    var that = this
    var orderID = e.currentTarget.dataset.orderid
    that.setData({
      orderID: orderID
    })
    wx.showModal({
      title: '提示',
      content: '确定删除吗？',
      success(res) {
        if (res.confirm) {
          that.del_ture()
        }
        else if (res.cancel) {
        }
      }
    })
  },
  del_ture: function (e) {
    var that = this
    var orderID = that.data.orderID
    var allorderlist = that.data.allorderlist
    app.util.request({
      url: testAddr + "facility_order/delOrder?orderID=" + orderID,
      method: "POST",
      data: {},
      success: function (res) {
        that.setData({
          allorderlist: [],
          pageIndex: 1
        })
        that.lookorder()
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    that.lookorder()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})